'use strict';
const db = uniCloud.database()
exports.main = async (event, context) => {
	const {classify,page=1,pageSize=10} = event;
	let matchObj = {}
	if(classify !== "全部"){
		matchObj = {classify}
	}
	const list = await db.collection('article')
	.aggregate()//聚合获取数据
	.match(matchObj)//根据条件获取对应数据
	.project({
		content:0,
	}).skip(pageSize*(page-1))//获取页数
	.limit(pageSize)//每一页获取的数据
	.end()
	
	//当前匹配的数据总数
	const {total} = await db.collection('article').where(matchObj).count()
	
	
	//返回数据给客户端
	return {
		code:0,
		msg:'数据获取成功',
		data:{total,articlList:list.data}
	}
};
